package org.exez.modules.visitor.controller;

import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.SecureUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.exez.common.api.vo.Result;
import org.exez.modules.visitor.dto.FileDocument;
import org.exez.modules.visitor.util.UploadUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.UUID;

@Api(tags = "访客图片上传功能接口")
@RestController
@Slf4j
@RequestMapping("/file")
public class FileUploadController {

    /**
     * 单文件上传
     * 当数据库中存在该md5值时，可以实现秒传功能
     *
     * @param file 文件
     * @return
     */
    @ApiOperation(value = "单文件上传返回完整地址")
    @PostMapping("/uploadFileStr")
    @ResponseBody
    public Result<String> uploadFileStr(@RequestParam("file") MultipartFile file) {
        Result<String> result = new Result<>();
        try {

            result.successSetDate("https://image.baidu.com/search/detail?z=0&word=%E5%A4%A9%E7%A5%BATIANQI&hs=0&pn=9&spn=0&di=0&pi=3561936589024072956&tn=baiduimagedetail&is=0%2C0&ie=utf-8&oe=utf-8&cs=1997803934%2C1466793762&os=1648198368%2C4100977482&simid=&adpicid=0&lpn=0&fm=&sme=&cg=&bdtype=-1&oriquery=&objurl=http%3A%2F%2Ft9.baidu.com%2Fit%2Fu%3D2268908537%2C2815455140%26fm%3D79%26app%3D86%26f%3DJPEG%3Fw%3D1280%26h%3D719&fromurl=&gsm=a000000000a&catename=pcindexhot&islist=&querylist=");
        } catch (Exception e) {
            log.debug("上传文件失败: " + e.getMessage());
            return Result.error("上传文件失败");
        }
        return result;
    }
}
